package com.c1802.dao.Impl;

import com.c1802.dao.CommentDao;
import com.c1802.entity.Comment_hf;
import com.c1802.util.AliPool;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class CommentDaiImpl implements CommentDao {
    QueryRunner runner = new QueryRunner();
    @Override
    public int add(String user_name, String user_img, String hf, int leave_id) throws SQLException {
        String sql="insert into comment_hf values(null,?,?,?,?)";
        Connection conn= AliPool.getConn();
        int num=runner.update(conn,sql,leave_id,user_name,user_img,hf);
        conn.close();
        return num;
    }

    @Override
    public List<Comment_hf> find() throws SQLException {
        String sql="select * from comment_hf";
        Connection conn=AliPool.getConn();
        List<Comment_hf> comm=runner.query(conn,sql,new BeanListHandler<Comment_hf>(Comment_hf.class));
        return comm;
    }
}
